package com.admin.persistence.sys.mapper;

import com.admin.persistence.sys.entity.Role;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author jack
 * @since 2019-05-03
 */
public interface RoleMapper extends BaseMapper<Role> {

    @Select("SELECT ROLE_.* FROM sys_role ROLE_" +
            "INNER JOIN" +
            "SYS_USER_ROLE USER_ROLE" +
            "ON" +
            "sys_user_role.ROLE_ID = ROLE_ID" +
            "WHERE USER_ROLE.USER_ID = #{userId}")
    List<Role> queryByUser(@Param("userId") String userId);

    @Select("SELECT ROLE_.* FROM sys_role ROLE_" +
            "INNER JOIN" +
            "sys_group_role GROUP_ROLE_" +
            "IN" +
            "GROUP_ROLE_.ROLE_ID = ROLE_.ID" +
            "WHERE GROUP_ROLE_.GROUP_ID=#{userGroupId}")
    List<Role> queryByUserGroup(@Param("userGroupId") String userGroupId);
}
